package cn.zh.stan.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.ArrayList;

import cn.zh.stan.ITem.CITem;
import cn.zh.stan.ITem.GaItem;
import cn.zh.stan.R;

/**
 * Created by WYN on 2018/1/17 0017.
 */

public class Gpladapter extends BaseAdapter {

    Context context;
    ArrayList<CITem> arrayList;
    LayoutInflater inflater;

    public Gpladapter(Context context,ArrayList<CITem> arrayList){
        this.context=context;
        this.arrayList=arrayList;
        inflater=LayoutInflater.from(context);
    }
    @Override
    public int getCount() {
        return arrayList.size();
    }

    @Override
    public Object getItem(int i) {
        return arrayList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        Holder holder=null;
        if (null==view){
            holder=new Holder();
            view=inflater.inflate(R.layout.gpl_layout,null,false);
            holder.tv=view.findViewById(R.id.gatxt);
            holder.gaimg=view.findViewById(R.id.gaimg);
            view.setTag(holder);
        }else {
            holder= (Holder) view.getTag();
        }
        holder.tv.setText(arrayList.get(i).getClassName());
        if (0==arrayList.get(i).getChildClass().length()){
            holder.gaimg.setVisibility(View.INVISIBLE);
        }else {
            holder.gaimg.setVisibility(View.VISIBLE);
        }

        return view;
    }


    public class Holder{
        TextView tv;
        ImageView gaimg;
    }


}
